package org.ihelpuoo.weboo.upload;

import org.ihelpuoo.db.sql.SQLUtils;
import org.ihelpuoo.lang.StringUtils;
import org.ihelpuoo.orm.IIIException;
import org.ihelpuoo.orm.filter.SQLFilter;

public class ThumbnailBeanFilter extends SQLFilter
{

	private static final long	serialVersionUID	= 3744569654680599174L;

	private String				keyword;
	private String				extension;
	private String				orderBy;

	public String getKeyword()
	{
		return keyword;
	}

	public void setKeyword(String keyword)
	{
		this.keyword = keyword;
	}

	public String getExtension()
	{
		return extension;
	}

	public void setExtension(String extension)
	{
		this.extension = extension;
	}

	public String getOrderBy()
	{
		return orderBy;
	}

	public void setOrderBy(String orderBy)
	{
		this.orderBy = orderBy;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (!super.equals(obj))
			return false;
		if (!this.keyword.equals(((ThumbnailBeanFilter)obj).keyword))
			return false;
		if (!this.extension.equals(((ThumbnailBeanFilter)obj).extension))
			return false;
		if (!this.orderBy.equals(((ThumbnailBeanFilter)obj).orderBy))
			return false;
		return true;
	}

	@Override
	public CharSequence getConditionString() throws IIIException
	{
		StringBuffer sb = new StringBuffer();
		if (!StringUtils.isBlank(keyword))
			sb.append("name LIKE '%").append(SQLUtils.escapteCondition(keyword)).append("%'");
		if (sb.length() > 0)
			sb.append(" AND ");
		if (!StringUtils.isBlank(extension))
			sb.append("extension IN (").append(extension).append(')');
		return sb;
	}

	@Override
	public CharSequence getOrderByString()
	{
		return this.getOrderBy();
	}

}
